package com.bcu.calculus.controller;

import com.bcu.calculus.UseToken;
import com.bcu.calculus.config.GlobalConfig;
import com.bcu.calculus.entity.Flist;
import com.bcu.calculus.entity.Message;
import com.bcu.calculus.service.FlistService;
import com.bcu.calculus.utils.LoadUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

@Api(tags = "13  第一路由模块")
@RestController
@RequestMapping("/api/Flist")
public class FlistConrtoller {

    @Resource
    private FlistService flistService;

    @Resource
    private GlobalConfig globalConfig;

    @ApiOperation(value = "上传管理端图片")
    @PostMapping(value = "/manageImages", headers = "content-type=multipart/form-data")
    public String getManageImages(@RequestParam(value = "file") MultipartFile[] files, HttpServletRequest request) throws IOException {
       return globalConfig.hostUrl + "bcucalculusFile/image/flist/manageimage/" + LoadUtil.upload(globalConfig.filePath+"image/flist/manageimage/", files, request);

    }

    @ApiOperation(value = "上传h5图片")
    @PostMapping(value = "/hfImages", headers = "content-type=multipart/form-data")
    public String gethfImages(@RequestParam(value = "file") MultipartFile[] files, HttpServletRequest request) throws IOException {
        return globalConfig.hostUrl + "bcucalculusFile/image/flist/hfiveimage/" + LoadUtil.upload(globalConfig.filePath+"image/flist/hfiveimage/", files, request);
    }

    @ApiOperation(value = "添加一级路由")
    @PostMapping(value = "/add")
    public Message<?> addFlist(Flist flist){
        return flistService.addFlist(flist);
    }

    @ApiOperation(value = "根据主键删除一级路由")
    @DeleteMapping(value = "/del")
    public Message<?> delFlist(String flistId){
        return flistService.delFlist(flistId);
    }

    @ApiOperation(value = "获取所有的一级路由")
    @PostMapping(value = "/getAll")
    public Message<List<Flist>> findAll(){
        return flistService.selectAllFlist();
    }

    @ApiOperation(value = "根据主键获取一级路由")
    @PostMapping(value = "/getOne")
    public Message<Flist> findOne(String flistId){
        return flistService.selectOneFlistById(flistId);
    }

    @ApiOperation(value = "更新一级路由")
    @PostMapping(value = "/update")
    public Message<?> updateFlist(Flist flist){
        return flistService.updateFlist(flist);
    }

    @ApiOperation(value = "通过二级路由Id获取一级路由")
    @GetMapping(value = "/getFlistBySlistId")
    public Message<Flist> getFlistBySlistId(String slistId){
        return flistService.getFlistBySlistId(slistId);
    }

}
